//
//  DoctorApplyController.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorApplyController.h"
#import "RcyDoctorApplyCell.h"
#import "YJDoctorsIfonModel.h"
#import "RcyDoctorApplyModel.h"
#import "RcyDoctorApplyDetailsViewController.h"
static NSString *cellID = @"cellID";

@interface DoctorApplyController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray<YJDoctorsIfonModel *> *modelList;

@property (nonatomic, strong) UITableView *tableview;


@end

@implementation DoctorApplyController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self getData];
    [self setupUI];
}

-(void)getData
{
    [YJDoctorsIfonModel getDoctorsIfonModellistComplete:^(NSArray<YJDoctorsIfonModel *> *modelList) {
        self.modelList = [NSMutableArray arrayWithArray:modelList];
        
        [self.tableview reloadData];
        
    }];
}


-(void)setupUI
{
    UITableView *table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableview = table;
    [self.view addSubview:table];
    
    [table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    
    self.tableview.rowHeight = 120;
    
    [self.tableview registerNib:[UINib nibWithNibName:@"RcyDoctorApplyCell" bundle:nil] forCellReuseIdentifier:cellID];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.modelList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RcyDoctorApplyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    YJDoctorsIfonModel *model = self.modelList[indexPath.row];
    
    cell.doctorModel = model;
    
//    
//    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
//    
//    cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YJDoctorsIfonModel *model = self.modelList[indexPath.row];
    
    RcyDoctorApplyDetailsViewController *detailVc = [[RcyDoctorApplyDetailsViewController alloc] initWithNibName:@"RcyDoctorApplyDetailsViewController" bundle:nil];
    detailVc.model = model;
    detailVc.indexpath = indexPath.row;
    
    detailVc.clickCancelBtn = ^(NSInteger index){
        
        [self.modelList removeObjectAtIndex:index];
        [self.tableview reloadData];
//        NSLog(@"%@",[NSThread currentThread]);
    };
    
    [self.navigationController pushViewController:detailVc animated:YES];
    
    
    
    
}


@end
